package cn.kgc.appinfo.controller;

import cn.kgc.appinfo.entity.DevUser;
import cn.kgc.appinfo.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private DevUserService devUserService;

    @RequestMapping("/login")
    public String login(){
        return "user/login";
    }

    @RequestMapping("/do_login")
    public String doLogin(DevUser devUser, Model model, HttpSession session){
        DevUser loginDevUser = devUserService.loginUser(devUser);
        if(null != loginDevUser){
            session.setAttribute("user",loginDevUser);
            return "redirect:/app_info/show_app";
        }else {
            model.addAttribute("msg","用户名或密码错");
            return "user/login";
        }
    }
}
